'\" t
.\"     Title: rename
.\"    Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
.\"      Date: 2024-12-16
.\"    Manual: User Commands
.\"    Source: util-linux 2.40.4
.\"  Language: English
.\"
.TH "RENAME" "1" "2024-12-16" "util\-linux 2.40.4" "User Commands"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.ss \n[.ss] 0
.nh
.ad l
.de URL
\fI\\$2\fP <\\$1>\\$3
..
.als MTO URL
.if \n[.g] \{\
.  mso www.tmac
.  am URL
.    ad l
.  .
.  am MTO
.    ad l
.  .
.  LINKSTYLE blue R < >
.\}
.SH "NAME"
rename \- rename files
.SH "SYNOPSIS"
.sp
\fBrename\fP [options] \fIexpression replacement file\fP...
.SH "DESCRIPTION"
.sp
\fBrename\fP will rename the specified files by replacing the first occurrence of \fIexpression\fP in their name by \fIreplacement\fP.
.SH "OPTIONS"
.sp
\fB\-s\fP, \fB\-\-symlink\fP
.RS 4
Do not rename a symlink but change where it points.
.RE
.sp
\fB\-v\fP, \fB\-\-verbose\fP
.RS 4
Show which files were renamed, if any.
.RE
.sp
\fB\-n\fP, \fB\-\-no\-act\fP
.RS 4
Do not make any changes; add \fB\-\-verbose\fP to see what would be made.
.RE
.sp
\fB\-a\fP, \fB\-\-all\fP
.RS 4
Replace all occurrences of \fIexpression\fP rather than only the first one.
.RE
.sp
\fB\-l\fP, \fB\-\-last\fP
.RS 4
Replace the last occurrence of \fIexpression\fP rather than the first one.
.RE
.sp
\fB\-o\fP, \fB\-\-no\-overwrite\fP
.RS 4
Do not overwrite existing files. When \fB\-\-symlink\fP is active, do not overwrite symlinks pointing to existing targets.
.RE
.sp
\fB\-i\fP, \fB\-\-interactive\fP
.RS 4
Ask before overwriting existing files.
.RE
.sp
\fB\-h\fP, \fB\-\-help\fP
.RS 4
Display help text and exit.
.RE
.sp
\fB\-V\fP, \fB\-\-version\fP
.RS 4
Print version and exit.
.RE
.SH "WARNING"
.sp
The renaming has no safeguards by default or without any one of the options \fB\-\-no\-overwrite\fP, \fB\-\-interactive\fP or \fB\-\-no\-act\fP. If the user has permission to rewrite file names, the command will perform the action without any questions. For example, the result can be quite drastic when the command is run as root in the \fI/lib\fP directory. Always make a backup before running the command, unless you truly know what you are doing.
.SH "EDGE CASES"
.sp
If the \fIexpression\fP is empty, then by default \fIreplacement\fP will be added to the start of the filename. With \fB\-\-all\fP, \fIreplacement\fP will be inserted in between every two characters of the filename, as well as at the start and end.
.sp
Normally, only the final path component of a filename is updated. (Or with \fB\-\-symlink\fP, only the final path component of the link.) But if either \fIexpression\fP or \fIreplacement\fP contains a \fI/\fP, the full path is updated. This can cause a file to be moved between folders. Creating folders, and moving files between filesystems, is not supported.
.SH "INTERACTIVE MODE"
.sp
As most standard utilities rename can be used with a terminal device (tty in short) in canonical mode, where the line is buffered by the tty and you press ENTER to validate the user input. If you put your tty in cbreak mode however, rename requires only a single key press to answer the prompt. To set cbreak mode, run for example:
.sp
.if n .RS 4
.nf
.fam C
sh \-c \*(Aqstty \-icanon min 1; "$0" "$@"; stty icanon\*(Aq rename \-i from to files
.fam
.fi
.if n .RE
.SH "EXIT STATUS"
.sp
\fB0\fP
.RS 4
all requested rename operations were successful
.RE
.sp
\fB1\fP
.RS 4
all rename operations failed
.RE
.sp
\fB2\fP
.RS 4
some rename operations failed
.RE
.sp
\fB4\fP
.RS 4
nothing was renamed
.RE
.sp
\fB64\fP
.RS 4
unanticipated error occurred
.RE
.SH "EXAMPLES"
.sp
Given the files \fIfoo1\fP, ..., \fIfoo9\fP, \fIfoo10\fP, ..., \fIfoo278\fP, the commands
.sp
.if n .RS 4
.nf
.fam C
rename foo foo00 foo?
rename foo foo0 foo??
.fam
.fi
.if n .RE
.sp
will turn them into \fIfoo001\fP, ..., \fIfoo009\fP, \fIfoo010\fP, ..., \fIfoo278\fP. And
.sp
.if n .RS 4
.nf
.fam C
rename .htm .html *.htm
.fam
.fi
.if n .RE
.sp
will fix the extension of your html files. Provide an empty string for shortening:
.sp
.if n .RS 4
.nf
.fam C
rename \*(Aq_with_long_name\*(Aq \*(Aq\*(Aq file_with_long_name.*
.fam
.fi
.if n .RE
.sp
will remove the substring in the filenames.
.SH "SEE ALSO"
.sp
\fBmv\fP(1)
.SH "REPORTING BUGS"
.sp
For bug reports, use the issue tracker at \c
.URL "https://github.com/util\-linux/util\-linux/issues" "" "."
.SH "AVAILABILITY"
.sp
The \fBrename\fP command is part of the util\-linux package which can be downloaded from \c
.URL "https://www.kernel.org/pub/linux/utils/util\-linux/" "Linux Kernel Archive" "."